package br.com.sadim.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.sadim.diagnostico.Sintoma;

public class SintomaDAOHibernate implements SintomaDAO{
	private Session session;
	public void setSession(Session s) {
		session = s;
	}

	@Override
	public void save(Sintoma sintoma) {
		session.save(sintoma);
	}

	@Override
	public void delete(Sintoma sintoma) {
		session.delete(sintoma);
	}

	@Override
	public void update(Sintoma sintoma) {
		session.update(sintoma);
	}

	@Override
	public Sintoma getById(Integer idSintoma) {
		return (Sintoma) session.get(Sintoma.class, idSintoma);
	}

	@Override
	public Sintoma getByNome(String nome) {
		String hql = "SELECT S FROM br.com.sadim.diagnostico.sintoma S WHERE S.nome = :param";
		Query consulta = session.createQuery(hql);
		consulta.setString("param", nome);
		
		return (Sintoma) consulta.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Sintoma> getList() {
		return session.createCriteria(Sintoma.class).list();
	}
}
